package com.xccwk;

import java.io.IOException;
import java.util.List;

import javax.security.auth.message.callback.PrivateKeyCallback.Request;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xccwk.constats.Constants;
import com.xccwk.model.User;
import com.xccwk.serviceImp.UserServiceImp;


@WebServlet("/he")
public class HelloLi extends HttpServlet{


	UserServiceImp imp=new UserServiceImp(); 

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		List<User> listUser;
		if(req.getParameter("id")!=null) {
			int id= Integer.parseInt(req.getParameter("id"));
			listUser=imp.findUserById(Constants.sql_select,id);
			System.out.println(listUser.toString());
			req.getSession().setAttribute("listUser",listUser);
			req.getSession().setAttribute("flag", false);

		}else {
			listUser=Constants.imp.findAll(Constants.sql_all);
			System.out.println(listUser.toString());
			req.getSession().setAttribute("listUser",listUser);
		}	
		resp.sendRedirect("login.jsp");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		doGet(req,resp);

	}




}
